package logic

import (
	"context"
	"errors"
	"shop/cache"

	"shop/shopRpc/internal/svc"
	"shop/shopRpc/shopRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDeleteLogic {
	return &CartDeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartDeleteLogic) CartDelete(in *shopRpc.CartDeleteRequest) (*shopRpc.CartDeleteResponse, error) {
	// todo: add your logic here and delete this line
	err := cache.CartDelete(in.UserId, in.GoodsId)
	if err != nil {
		return nil, errors.New("删除失败")
	}
	return &shopRpc.CartDeleteResponse{
		Success: true,
	}, nil
}
